package com.course.${module}.controller.admin;/**
 * @author: lin
 */


import com.course.server.config.LogAspect;
import com.course.server.domain.${Domain};
import com.course.server.dto.${Domain}Dto;
import com.course.server.dto.PageDto;
import com.course.server.dto.ResponseDto;
import com.course.server.exception.ValidatorException;
import com.course.server.service.${Domain}Service;
import com.course.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *@Author lin
 *@Data Created in 2020/7/28 16:04
 *Description 测试类
 *@Modified By
 *@Version V1.0
 */
@RestController
@RequestMapping("/admin/${domain}")
public class ${Domain}Controller {
    private static final Logger LOG = LoggerFactory.getLogger(${Domain}Controller.class);
    public static final String BUSINESS_NAME = "${tableNameCn}";
    @Resource
    private ${Domain}Service ${domain}Service;
    @PostMapping("/list")
    /**
     * create by: lin
     * description: 列表查询
     * create time: 2020/8/2 17:39
     */
    public ResponseDto list(@RequestBody PageDto pageDto){
        ResponseDto responseDto = new ResponseDto();
        ${domain}Service.list(pageDto);
        responseDto.setContent(pageDto);
        return responseDto;
    }
    /**
     * create by: lin
     * description: 保存 id有值时更新，无值时新增
     * create time: 2020/8/2 17:40
     */
    @PostMapping("/save")
    public ResponseDto save(@RequestBody ${Domain}Dto ${domain}Dto){
        //保存校验
<#list fieldList as field>
    <#if field.name!="id" && field.nameHump!="createdAt" && field.nameHump!="updatedAt" && field.nameHump!="sort">
        <#if !field.nullAble>
            ValidatorUtil.require(${domain}Dto.get${field.nameBigHump}(), "${field.nameCn}");
        </#if>
        <#if (field.length > 0)>
            ValidatorUtil.length(${domain}Dto.get${field.nameBigHump}(), "${field.nameCn}", 1, ${field.length?c});
        </#if>
    </#if>
</#list>
        ResponseDto responseDto = new ResponseDto();
        ${domain}Service.save(${domain}Dto);
        return responseDto;
    }
    /**
     * create by: lin
     * description: 删除
     * create time: 2020/8/2 17:58
     */
    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable String id){
        ResponseDto responseDto = new ResponseDto();
        ${domain}Service.delete(id);
        return responseDto;
    }
}
